#include <stdio.h>
#include <string.h>

const int Char_Set = 26;
const int Limit_Size = 100;

bool e[ Char_Set ][ Char_Set ];

void init( )
{
    int i, j;
    for ( i = 0; i < Char_Set; i++ )
        for ( j = 0; j < Char_Set; j++ )
            e[ i ][ j ] = false;
}

void setEdge( int a, int b )
{
    e[ a - 'a' ][ b - 'a' ] = true;
}

bool work( )
{
    int i, j, k;
    for ( k = 0; k < Char_Set; k++ )
        for ( i = 0; i < Char_Set; i++ )
            for ( j = 0; j < Char_Set; j++ )
                e[ i ][ j ] = e[ i ][ j ] || ( e[ i ][ k ] && e[ k ][ j ] );
    return e[ 'b' - 'a' ][ 'm' - 'a' ];
}

int main( )
{
    char data[ Limit_Size ];
    init( );
    while ( gets( data ) )
    {
        if ( data[ 0 ] == '0' )
        {
            if ( work( ) )
                puts("Yes.");
            else
                puts("No.");
            init( );
        }
        else
            setEdge( data[ 0 ], data[ strlen( data ) - 1 ] );
    }
    return 0;
}
